
const loadSystem = (app, router) => {
  let loadedSystem = {}
  return function (systemName, routes) {
    if (loadedSystem[systemName]) return
    return new Promise((resolve, reject) => {
      let script = document.createElement('script')
      script.src = `/subSystem/${systemName}.min.js?t=${Date.now()}`
      script.addEventListener('load', _ => {
        try {
          const system = window && window[systemName]
          app.use(system)
          system.addRoutes.call(app, router, routes)
          loadedSystem[systemName] = true
          resolve()
        } catch (err) {
          console.log(err)
          console.log(`${systemName}系统加载错误`)
          reject()
        }
      })
      document.head.appendChild(script)
    })

  }
}

// export default loadSystem(app,router)

export default loadSystem